package com.lm.liaoming.tool;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.lm.liaoming.R;


/**
 * 显示dialog的Utils
 * 韦敏敏
 */

public class DiaLogUtils {
    public interface OnOKClickLisenter {
        void OnClick();

        void dismiss();
    }


    /**
     * @param mContext          当前环境
     * @param textContent       左边按钮内容
     * @param onOKClickLisenter 回调
     */
    public static void showDialog(final Context mContext, String textContent, final OnOKClickLisenter onOKClickLisenter) {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        final AlertDialog alertDialog = builder.create();
        alertDialog.show();
        alertDialog.getWindow().setContentView(R.layout.check_version_update_dialog_new);
        Button closeBtn = alertDialog.getWindow().findViewById(R.id.btn_cancel);
        TextView upgradeText = alertDialog.getWindow().findViewById(R.id.tv_upgrade_text);
        upgradeText.setText(textContent);
        Button upgradeBtn = alertDialog.getWindow().findViewById(R.id.btn_update);
        upgradeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                onOKClickLisenter.OnClick();
            }
        });
        closeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                alertDialog.dismiss();
                onOKClickLisenter.dismiss();

            }
        });
        alertDialog.setCancelable(true);
        alertDialog.setCanceledOnTouchOutside(false);
        alertDialog.show();
    }

    /**
     * @param mContext          当前环境
     * @param titles            设置标题
     * @param subtitle       设置副标题
     * @param rightname         设置左边按钮内容
     * @param onOKClickLisenter 回调
     */
    public static void showDialog(final Context mContext, String titles, String subtitle, String rightname, final OnOKClickLisenter onOKClickLisenter) {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        final AlertDialog alertDialog = builder.create();
        alertDialog.show();
        alertDialog.getWindow().setContentView(R.layout.check_version_update_dialog_new);
        Button closeBtn = alertDialog.getWindow().findViewById(R.id.btn_cancel);
        TextView title = alertDialog.getWindow().findViewById(R.id.title);
        title.setText(titles);
        closeBtn.setTextColor(Color.parseColor("#009e9f"));
        TextView upgradeText = alertDialog.getWindow().findViewById(R.id.tv_upgrade_text);
        upgradeText.setText(subtitle);
        Button upgradeBtn = alertDialog.getWindow().findViewById(R.id.btn_update);
        upgradeBtn.setTextColor(Color.parseColor("#009e9f"));
        upgradeBtn.setText(rightname);
        upgradeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                onOKClickLisenter.OnClick();
            }
        });
        closeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                alertDialog.dismiss();
                onOKClickLisenter.dismiss();
            }
        });
        alertDialog.setCancelable(true);
        alertDialog.setCanceledOnTouchOutside(false);
        alertDialog.show();
    }
}
